package com.singzi.leetcode.N1200;

public class T1154 {
    public static void main(String[] args) {
        Solution1154 solution1154 = new Solution1154();
        String date = "2008-10-10";
        System.out.println(solution1154.dayOfYear(date));

    }
}
class Solution1154 {
    public int dayOfYear(String date) {

        int[] months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

        String year = date.substring(0,4);
        int month = Integer.parseInt(date.substring(5,6))*10 + Integer.parseInt(date.substring(6,7));
        for (int i = 0; i < month-1; i++) {
            months[0] +=months[i];
        }
        int day = Integer.parseInt(date.substring(8,9))*10 + Integer.parseInt(date.substring(9,10));
        if(month >2&&isLeapYear(year)) day++;
        return months[0]-31+day;

    }
    public boolean isLeapYear(String sTear){
        int year = Integer.parseInt(sTear);
        return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
    }
}